/**
 * Copyright 2004 - 2007 Blue Bamboo International Inc. 
 *           All rights reserved.
 *
 *
 * Blue Bamboo PROPRIETARY/CONFIDENTIAL.
 *
 */

package com.bluebamboo.bluetools.pingpang.bean;

import org.apache.mina.core.service.IoHandler;

import com.bluebamboo.bluetools.pingpang.connection.IConnectionHandler;

/**
 * DOCME
 * 
 * @author tanxuqing
 * @date Sep 12, 2009
 * @since
 */
public abstract class ConnectionBean {

    public static final int TYPE_TCP_SERVER = 1;
    public static final int TYPE_TCP_CLIENT = 2;
    public static final int TYPE_UDP_SERVER = 3;
    public static final int TYPE_UDP_CLIENT = 4;
    public static final int TYPE_SERIAL = 5;

    private String name;
    private int type;

    private IConnectionHandler connectionHandler;
    private IoHandler ioHandler;

    /**
     * @param name
     */
    public ConnectionBean(String name, int type) {
        super();
        this.name = name;
        this.type = type;
    }

    /**
     * Get the <code>IConnectionHandler</code>, if one <code>IConnectionHandler</code> has been instantiated, the old
     * instance returned
     * 
     * @return
     * @LazyInitializationHolder 
     */
    public IConnectionHandler getConnectionHandler() {
        if (connectionHandler == null)
            connectionHandler = createConnectionHandler();
        return connectionHandler;
    }

    /**
     * @return
     * @LazyInitializationHolder
     */
    public IoHandler getIoHandler() {
        if (ioHandler == null)
            ioHandler = createIoHandler();
        return ioHandler;
    }

    abstract public IConnectionHandler createConnectionHandler();

    abstract public IoHandler createIoHandler();

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the type
     */
    public int getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(int type) {
        this.type = type;
    }

}
